package tech.yunland.shop.domain.dao;

import com.moyuer.bsf.domain.dao.BaseDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import tech.yunland.shop.domain.model.JobPrize;

import java.math.BigDecimal;
import java.util.List;

/**
 * 职位提成
 * 
 * @author 王东阳<350456985@qq.com> 16/4/22
 */
@Repository
public class JobPrizeDao extends BaseDao<JobPrize, String> {

	/**
	 * 查询提成值
	 * 
	 * @param organId
	 * @param jobId
	 * @return JobPrize
	 */
	public BigDecimal getJobpPrize(String organId, String jobId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(JobPrize.class);
		criteria.createCriteria("job").add(Restrictions.idEq(jobId));
		criteria.add(Restrictions.eq("state", 1));
		criteria.add(Restrictions.eq("organId", organId));
		List<JobPrize> list = this.findByCriteria(criteria);

		if (list != null && list.size() > 0){
			return list.get(0).getPrizeValue();
		}else {
			return BigDecimal.ZERO;
		}

	}
}